part of '../framework.dart';

/// 一个自定义的绘画，它必然包含一个路径[Path]和一个画笔[Paint]
/// 要注意的是，它的最终结果是无体积的，是一个点状的形式
/// 定义这个class主要是为了避免需要同时指定2个class（还有[CustomPainter]）才能自定义路径绘图
/// 使用此class就会显得简单很多
class PointDraw extends StatelessWidget {
  final Path path;
  final Paint paint;
  const PointDraw({
    required this.path,
    required this.paint,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      painter: _Painter(
        (canvas) => canvas.drawPath(path, paint),
      ),
    );
  }
}

/// 必须使用Painter的辅助（因为要extend）才能完成Drawing class
class _Painter extends CustomPainter {
  final Function(Canvas) render;
  const _Painter(this.render);

  @override
  void paint(Canvas canvas, Size size) => render(canvas);

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}
